/******************************************************************************

	COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2010.

	This file is part of Maxsi Engine.

	Maxsi Engine is free software: you can redistribute it and/or modify it
	under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or (at your
	option) any later version.

	Maxsi engine is distributed in the hope that it will be useful, but WITHOUT
	ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
	FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
	for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with Maxsi Engine. If not, see <http://www.gnu.org/licenses/>.

	MaxsiEngine.dll
	A general purpose C++ library for the Maxsi Technology Project.

	MaxsiCRuntime.h
	Turns out MinGW/GCC doesn't support as much useful stuff as Microsoft, so
	we have to implement it ourselves!

******************************************************************************/

#if !defined(MaxsiCRuntime_H) && defined(__GNUC__)
#define MaxsiCRuntime_H

//=============================================================================
//	Includes
//=============================================================================
#include <time.h>

//=============================================================================
//	Type declarations
//=============================================================================
typedef int errno_t; // TODO: Find out where errno_t is defined in POSIX!

BeginMaxsiNamespace

//=============================================================================
//	C Runtime extensions for MinGW
//=============================================================================
LINK	int strcat_s(char* strDestination, size_t numberOfElements, const char* strSource);
LINK	int wcscat_s(wchar_t* strDestination, size_t numberOfElements, const wchar_t* strSource);

LINK	int strcpy_s(char* strDestination, size_t numberOfElements, const char* strSource);
LINK	int wcscpy_s(wchar_t* strDestination, size_t numberOfElements, const wchar_t* strSource);

#if 0 // Deprecated by Maxsi::PrintString

LINK	int	_itoa_s(int value, char *buffer, size_t sizeInCharacters, int radix);
LINK	int	_itow_s(int value, wchar_t *buffer, size_t sizeInCharacters, int radix);

LINK	int	_uitoa_s(int value, char *buffer, size_t sizeInCharacters, int radix);
LINK	int	_uitow_s(int value, wchar_t *buffer, size_t sizeInCharacters, int radix);

LINK	int	_i64toa_s(int64_t value, char *buffer, size_t sizeInCharacters, int radix);
LINK	int	_i64tow_s(int64_t value, wchar_t *buffer, size_t sizeInCharacters, int radix);

LINK	int	_ui64toa_s(uint64_t value, char *buffer, size_t sizeInCharacters, int radix);
LINK	int	_ui64tow_s(uint64_t value, wchar_t *buffer, size_t sizeInCharacters, int radix);

LINK	int _gcvt_s(char *buffer, size_t sizeInBytes, double value, int digits);

#endif

#if 0
#ifdef __MINGW_H // __time64_t seems to create problems on Linux
LINK	errno_t	_gmtime64_s(tm* _tm, const __time64_t* time);
#endif
#endif
LINK	errno_t	asctime_s(char* buffer, size_t numberOfElements, const struct tm *_tm);
LINK	errno_t _get_errno(int * _Value);

EndMaxsiNamespace

#endif
